package com.twu.biblioteca.ui;

/**
 * This class represents a menu item, which can be selected from a Menu.
 */
public class MenuItem {

    private final String shortcut;
    private final String description;
    private final MenuItemHandler handler;
    private final boolean showWhenLoggedInOnly;

    public MenuItem(String shortcut, String description) {
        this(shortcut, description, null, false);
    }

    public MenuItem(String shortcut, String description, boolean showWhenLoggedInOnly) {
        this(shortcut, description, null, showWhenLoggedInOnly);
    }

    public MenuItem(String shortcut, String description, MenuItemHandler handler) {
        this(shortcut, description, handler, false);
    }

    public MenuItem(String shortcut, String description, MenuItemHandler handler, boolean showWhenLoggedInOnly) {
        this.shortcut = shortcut;
        this.description = description;
        this.handler = handler;
        this.showWhenLoggedInOnly = showWhenLoggedInOnly;
    }

    public String getShortcut() {
        return shortcut;
    }

    public String getDescription() {
        return description;
    }

    public void select() {
        if (handler == null) return;
        handler.handle();
    }

    public boolean isVisible(boolean isLoggedIn) {
        if (showWhenLoggedInOnly) return isLoggedIn;
        else return true;
    }
}
